' ***^^^***|||***^^^***
' 
'  This file is regenerated until it's edited. Delete the file to force regeneration.

'  NOTE: This denotes the way the file was created and it's possible the 
'        generation type has since changed.
'        Check the generation script for the curent state of the file.

' %%%###%%%8cca2d082b147e14aa6242df6de599f9%%%###%%%
' %%%##NoWS##%%%89a3a0573aab2463e645119e5045e087%%%##NoWS##%%%
' ***^^^***|||***^^^***

  
'************************************************************************************
' Copyright © 2003-2006 Kathleen Dollard
'
' This software is provided 'as-is', without any express or implied warranty. In no 
' event will the author be held liable for any damages arising from the use of this
' software.
' 
' You may use this software for any purpose, including commercial applications, 
' and you may redistribute this software as part of application delivery: however, 
' this copyright notice may not be removed and you may not otherwise redistribute 
' this software directly other than providing a link to wwww.gendotnet.com. 
'
' You may alter this software to better server your needs (I'd like to hear about your 
' changes in order to make the software better). If you alter the softwre, you must  
' clearly mark it as altered and must not be misrepresented as the original software.
' nor wholly your original work.
'*************************************************************************************

Option Explicit On
Option Strict On

Imports System
Imports System.Collections.Generic



Public Class MapProperty
   'Public Sub New(ByVal MapMappingRoot As MapMappingRoot, _
   '               ByVal Name As System.String)
   '   Me.New(MapMappingRoot, Name, Nothing, Nothing)
   'End Sub

   'Public Sub New(ByVal MapMappingRoot As MapMappingRoot, _
   '               ByVal Name As System.String, _
   '               ByVal tableName As String, _
   '               ByVal isReadOnly As Boolean)
   '   Me.New(MapMappingRoot, Name, Nothing, tableName, isReadOnly, tableName)
   'End Sub

   Public Sub New(ByVal MapMappingRoot As MapMappingRoot, _
                  ByVal name As System.String, _
                  ByVal columnName As String, _
                  ByVal tableName As String, _
                  ByVal tableAlias As String)
      Me.New(MapMappingRoot, Name, columnName, tableName, Nothing, tableAlias)
   End Sub

   Public Sub New(ByVal MapMappingRoot As MapMappingRoot, _
                  ByVal name As System.String, _
                  ByVal columnName As String, _
                  ByVal tableName As String, _
                  ByVal isReadOnly As Boolean, _
                  ByVal tableAlias As String)
      Me.New(MapMappingRoot, name, columnName, tableName, isReadOnly, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
                  Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
                  Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, tableAlias, Nothing, Nothing, Nothing, _
                  Nothing, Nothing)
   End Sub

   Public Sub New(ByVal MapMappingRoot As MapMappingRoot, _
                  ByVal name As System.String, _
                  ByVal columnName As String, _
                  ByVal tableName As String, _
                  ByVal isReadOnly As Boolean, _
                  ByVal tableAlias As String, _
                  ByVal isPrimaryKey As Nullable(Of Boolean), _
                  ByVal columnAlias As String)
      Me.New(MapMappingRoot, Name, columnName, tableName, isReadOnly, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, _
                  Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, isPrimaryKey, _
                  Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, tableAlias, Nothing, Nothing, Nothing, _
                  Nothing, columnAlias)
   End Sub

End Class

Public Class MapPropertyCollection
   Public Function Clone() As MapPropertyCollection
      Dim ret As New MapPropertyCollection
      For Each prop As MapProperty In Me
         ret.Add(prop)
      Next
      Return ret
   End Function

   Public Function GetProperty( _
             ByVal name As String, _
             ByVal ignoreCase As Boolean) _
             As MapProperty
      Dim stringComparison As StringComparison = stringComparison.InvariantCulture
      If ignoreCase Then
         stringComparison = System.StringComparison.InvariantCultureIgnoreCase
      End If
      For Each prop As MapProperty In Me
         If String.Compare(prop.Name, name, stringComparison) = 0 Then
            Return prop
         End If
      Next
      Return Nothing
   End Function

   Public Function GetProperty( _
             ByVal name As String) _
             As MapProperty
      Return GetProperty(name, False)
   End Function

   Public Function GetPropertyByColumnName( _
            ByVal tableName As String, _
            ByVal columnName As String) _
            As MapProperty
      For Each prop As MapProperty In Me
         If prop.ColumnName = columnName And prop.TableName = tableName Then
            Return prop
         End If
      Next
      Return Nothing
   End Function

   Public Function GetPropertyByColumnNameMainTable( _
            ByVal columnName As String) _
            As MapProperty
      If Me.Count = 0 Then
         Return Nothing
      End If
      Dim mainTableName As String = Me(0).TableName
      For Each prop As MapProperty In Me
         If prop.ColumnName = columnName And prop.TableName = mainTableName Then
            Return prop
         End If
      Next
   End Function

   ''' <summary>
   ''' Returns a column based on the column name. This ignores
   ''' the table name so should be used with great caution
   ''' </summary>
   ''' <param name="columnName"></param>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Function GetPropertyByColumnName( _
            ByVal columnName As String) _
            As MapProperty
      For Each prop As MapProperty In Me
         If prop.ColumnName = columnName Then
            Return prop
         End If
      Next
      Return Nothing
   End Function

   'Public Function GetPropertyByAnyColumnName( _
   '         ByVal columnName As String) _
   '         As MapProperty
   '   For Each prop As MapProperty In Me
   '      If prop.ColumnName = columnName Then
   '         Return prop
   '      End If
   '   Next
   '   Return Nothing
   'End Function

   ''' <summary>
   ''' Looks first for property name, then column in first table, then
   ''' column in any table in the objectdef's main recordset. Never 
   ''' searches child recordsets.
   ''' </summary>
   ''' <param name="tableName"></param>
   ''' <param name="name"></param>
   ''' <returns></returns>
   ''' <remarks></remarks>
   Public Function GetPropertyByPreferredName( _
          ByVal tableName As String, _
          ByVal name As String, _
          ByVal columnName As String) _
          As MapProperty
      For Each prop As MapProperty In Me
         If prop.Name = name Then
            Return prop
         End If
      Next
      For Each prop As MapProperty In Me
         If prop.ColumnName = columnName And prop.TableName = tableName Then
            Return prop
         End If
      Next
      For Each prop As MapProperty In Me
         If prop.ColumnName = columnName Then
            Return prop
         End If
      Next
      Return Nothing
   End Function

End Class

	